package com.spc.car.data.domain.base.po;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spc.car.data.entity.base.BaseProjectType;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;

@Data
public class ProjectTypeQueryPO {
    @Pattern(regexp = "[0-9]{8}", message = "项目类型编码错误")
    private String code;
    @Pattern(regexp = "[0-9]{8}", message = "父类编码错误")
    private String parentCode;
    @Length(max = 100, message = "项目类型名称错误")
    private String name;
    @Min(value = 1, message = "层级错误")
    private Integer level;

    public Wrapper toWrapper() {
        LambdaQueryWrapper<BaseProjectType> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(parentCode), BaseProjectType::getParentCode, parentCode)
                .eq(StringUtils.isNotBlank(code), BaseProjectType::getCode, code)
                .like(StringUtils.isNotBlank(name), BaseProjectType::getName, name)
                .eq(null != level, BaseProjectType::getLevel, level)
                .eq(BaseProjectType::getStatus, "A")
                .orderByAsc(BaseProjectType::getCode);
        return wrapper;
    }
}
